package com.fxkj.cloud.drms.application.impl;

import com.fxkj.cloud.dbs.common.constants.DataType;
import com.fxkj.cloud.dbs.common.model.alarmItem.ProductAlarmItemCreate;
import com.fxkj.cloud.drms.application.ProductApplicationService;
import com.fxkj.cloud.drms.domain.mqtt.CommandAndQuerySender;
import com.fxkj.cloud.drms.domain.ts.repository.TimeseriesRepository;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
 * <p>description: </p>
 * @author ww
 * @date 2025/3/18 13:45
 */
@Component
public class ProductApplicationServiceImpl implements ProductApplicationService {

    private final TimeseriesRepository timeseriesRepository;
    private final CommandAndQuerySender commandAndQuerySender;


    public ProductApplicationServiceImpl(TimeseriesRepository timeseriesRepository, CommandAndQuerySender commandAndQuerySender) {
        this.timeseriesRepository = timeseriesRepository;
        this.commandAndQuerySender = commandAndQuerySender;
    }

    @Override
    public void createProduct(UUID rootOrganizationId, UUID productId, Map<String, DataType> attributeKeyDataTypeMap) {
        timeseriesRepository.createSuperTable(rootOrganizationId, productId, attributeKeyDataTypeMap);
    }

    @Override
    public void addProductAttribute(UUID productId, Map<String, DataType> attributeKeyDataTypeMap, Set<String> deviceSerialNos, List<ProductAlarmItemCreate> productAlarmItemCreates) {
        //时序库中添加对应的属性
        timeseriesRepository.addProductAttribute(productId, attributeKeyDataTypeMap);
//        //推送对应的设备告警项设置
//        commandAndQuerySender.alarmAttributeCreate(deviceSerialNos, productAlarmItemCreates);
    }

    @Override
    public void removeProductAttribute(UUID productId, Set<String> attributeKeys) {
        timeseriesRepository.removeProductAttribute(productId, attributeKeys);
    }
}
